package com.lbs.jiepiaisi.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.base.BaseActivity;
import com.lbs.jiepiaisi.bean.EquipmentEntity;
import com.lbs.jiepiaisi.biz.SelCarsBiz;
import com.lbs.jiepiaisi.utils.Constant;
import com.lbs.jiepiaisi.view.WaitingDialogControll;

import java.util.List;

/**
 *
 * 时间：2017/10/23 21:04
 * 作用：用户信息
 */
public class AccountUserInfoActivity extends BaseActivity{
    private EquipmentEntity equipmentEntity;
    private SelCarsReceiver selCarsReceiver;//接收坐标点的广播
    private TextView tv_shebei;
    private TextView tv_xinghao;
    private TextView tv_sim;
    private TextView tv_chuchang;
    private TextView tv_daoqi;
    private TextView tv_name;
    private TextView tv_tel;
    private TextView tv_card;
    private TextView tv_hetong;
    private TextView tv_time;
    private TextView tv_chepai;
    private TextView tv_chexing;
    private TextView tv_fadong;
    private TextView tv_chejia;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isTemplate=true;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_content);
        titleView.setText("用户信息");
        templateButtonLeft.setVisibility(View.VISIBLE);
        selCarsReceiver=new SelCarsReceiver();
        getApplicationContext().registerReceiver(selCarsReceiver, new IntentFilter(Constant.ACCOUNT_USER_INFO));
        findView();
        setLinstener();
        getExras();
    }

    private void findView(){
        templateButtonLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tv_shebei = (TextView)findViewById(R.id.tv_shebei);
        tv_xinghao = (TextView)findViewById(R.id.tv_xinghao);
        tv_sim = (TextView)findViewById(R.id.tv_sim);
        tv_chuchang = (TextView)findViewById(R.id.tv_chuchang);
        tv_daoqi = (TextView)findViewById(R.id.tv_daoqi);
        tv_name = (TextView)findViewById(R.id.tv_name);
        tv_tel = (TextView)findViewById(R.id.tv_tel);
        tv_card = (TextView)findViewById(R.id.tv_card);
        tv_hetong = (TextView)findViewById(R.id.tv_hetong);
        tv_time = (TextView)findViewById(R.id.tv_time);
        tv_chepai = (TextView)findViewById(R.id.tv_chepai);
        tv_chexing = (TextView)findViewById(R.id.tv_chexing);
        tv_fadong = (TextView)findViewById(R.id.tv_fadong);
        tv_chejia = (TextView)findViewById(R.id.tv_chejia);
    }

    private void setLinstener(){

    }
    private void getExras(){
        WaitingDialogControll.showWaitingDialog(this);
        SelCarsBiz selCarsBiz=new SelCarsBiz();
        selCarsBiz.selCarsBizAccountInfo(getIntent().getStringExtra("eqNo"),
                "1","1000", getIntent().getStringExtra("deptId"), false, Constant.ACCOUNT_USER_INFO);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getApplicationContext().unregisterReceiver(selCarsReceiver);
    }

    class SelCarsReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            WaitingDialogControll.dismissWaitingDialog();

            equipmentEntity=(EquipmentEntity) intent.
                    getSerializableExtra(Constant.KEY_DATA);
            WaitingDialogControll.dismissWaitingDialog();
            if(equipmentEntity.getCode()==Constant.STATUS_OK){
                List<EquipmentEntity.Result.Item> items =  equipmentEntity.getResult().getItems();
                if(items.size() > 0){
                    EquipmentEntity.Result.Item item = items.get(0);
                    tv_shebei.setText("设备号："+item.getEqNo());
                    tv_xinghao.setText("型号："+item.getEqModel());
                    tv_sim.setText("SIM卡号："+item.getSim());
                    tv_chuchang.setText("出厂时间："+item.getCreateTime());
                    tv_daoqi.setText("到期时间："+item.getExpTime());
                    tv_name.setText("车主姓名："+item.getOwnerName());
                    tv_tel.setText("车主电话："+item.getPhone());
                    tv_card.setText("身份证号："+item.getOwenerId());
                    tv_hetong.setText("合同号："+item.getContractNo());
                    tv_chepai.setText("车牌号："+item.getPlateNum());
                    tv_chexing.setText("车辆型号："+item.getvModel());
                    tv_fadong.setText("发动机号："+item.getEngineNo());
                    tv_chejia.setText("车架号："+item.getVin());
                }

            }else if(equipmentEntity.getCode()==Constant.STATUS_NETWORK_ERROR){
                Toast.makeText(mContext, "加载失败", Toast.LENGTH_SHORT).show();
            }else if(equipmentEntity.getCode()==Constant.STATUS_NO_NET){
                Toast.makeText(mContext, "请检查网络", Toast.LENGTH_SHORT).show();
            }

        }
    }
}
